package com.hyts.apilog.logger;

import com.hyts.apilog.bean.AspectjBean;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.apilog.banner
 * author:Libo/Alex
 * create-date:2019-06-15 22:42
 * copyright:libo-hyts-github
 * email:libo2dev@aliyun.com
 * description:此类主要用于: 系统默认的logger服务
 */
@Slf4j
public class DefaultLoggerAspectText implements LoggerAspectText<AspectjBean>{

    @Override
    public void beforeLoggerText(AspectjBean param) {
        log.info(LoggerText.ASPECTJ_START_TEXT,LoggerText.ASPECTJ_BEFORE_TEXT,
                param.getClassName(),param.getMethodName(),param.getParamArray());
        beforeMethod(param.getJoinPoint());
    }
    @Override
    public void afterLoggerText(AspectjBean param) {
        log.info(LoggerText.ASPECTJ_START_TEXT,LoggerText.ASPECTJ_AFTER_TEXT,
                param.getClassName(),param.getMethodName(),param.getParamArray());
        afterMethod(param.getJoinPoint());
    }
    @Override
    public void aroundLoggerText(AspectjBean param) {
        log.info(LoggerText.ASPECTJ_START_TEXT,LoggerText.ASPECTJ_AROUND_TEXT,
                param.getClassName(),param.getMethodName(),param.getParamArray());
        aroundMethod(param.getJoinPoint());
    }
    @Override
    public void afterReturnLoggerText(AspectjBean param) {
        log.info(LoggerText.ASPECTJ_START_TEXT,LoggerText.ASPECTJ_AFTER_RETURN_TEXT,
                param.getClassName(),param.getMethodName(),param.getParamArray());
        returnMethod(param.getJoinPoint());
    }
    @Override
    public void afterErrorLoggerText(AspectjBean param) {
        log.error(LoggerText.ASPECTJ_START_TEXT,LoggerText.ASPECTJ_AFTER_ERROR_TEXT,
                param.getClassName(),param.getMethodName(),param.getParamArray(),LoggerText.ASPECTJ_ERROR_TEXT,param.getThrowable().getMessage());
        errorMethod(param.getJoinPoint());
    }

    protected void beforeMethod(JoinPoint joinPoint){
        throw new UnsupportedOperationException("please implements the method");
    }

    protected void afterMethod(JoinPoint joinPoint){
        throw new UnsupportedOperationException("please implements the method");
    }

    protected void aroundMethod(JoinPoint joinPoint){
        throw new UnsupportedOperationException("please implements the method");
    }

    protected void returnMethod(JoinPoint joinPoint){
        throw new UnsupportedOperationException("please implements the method");
    }

    protected void errorMethod(JoinPoint joinPoint){
        throw new UnsupportedOperationException("please implements the method");
    }

}
